#include <iostream>
#include <vector>
#include <iomanip>
#include <commify.h>

#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assert.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/split_lg.hpp>
#include <perlutil.h>
#include <ultoa.h>

using std::vector;
using std::string;
using std::cout;
using std::cerr;
using boost::algorithm::split_n;
using boost::algorithm::join;
using boost::algorithm::split;
using boost::algorithm::is_any_of;
using boost::bind;

#include <is_equal_to.h>

int main (int argc, char *argv[])
{
	using namespace boost::assign; // bring 'operator+=()' into scope


	// number of items
	unsigned ITEMS_COUNT = 1000;
	cerr << "Maximum number of split items = " << ITEMS_COUNT << "\n";

	std::vector<string> vs;
	vs += "A", "AB";

	string joined_string =  join(vs, ":") + "*:?" + join(vs, "?");

	// Original string
	std::cerr << "Original String = \n    ";
	std::cerr << joined_string << "\n";

	// 
	// Old library results
	// 
	std::cerr << "Old library results = \n";
	std::vector<string> components;
	perl_split(joined_string, ":*?", perlutil::eCOUNT_EMPTY, components, ITEMS_COUNT);
	cerr << "    [\n";
	BOOST_FOREACH(string s, components) 
		cerr << "\t[" << s << "]\n";
	cerr << "    ]\n";



	// 
	// Adapted from boost code
	// 
	std::cerr << "Adapted from boost code = \n";
	components.clear();
//	boost::algorithm::split_n( components, joined_string, is_any_of (":*?"), ITEMS_COUNT);
	boost::algorithm::split_n( components, joined_string,  is_equal_to('?'), ITEMS_COUNT);
	cerr << "    [\n";
	BOOST_FOREACH(string s, components) 
		cerr << "\t[" << s << "]\n";
	cerr << "    ]\n";
	return(0);
}




